package com.qfedu.labsystem.controller;

import com.github.pagehelper.PageInfo;
import com.qfedu.labsystem.entity.bo.UserBO;
import com.qfedu.labsystem.entity.dto.*;
import com.qfedu.labsystem.entity.vo.ResultOBJ;
import com.qfedu.labsystem.entity.vo.UserVO;
import com.qfedu.labsystem.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName UserController
 * @Author ykx
 * @Date 2024/4/6 8:33
 * @Version 1.0
 */
@RestController
@RequestMapping("/adminapi/users")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping
    public PageInfo<UserVO> getUserList(BasePageDTO basePageDTO) {
        return userService.getUserList(basePageDTO);
    }

    @PostMapping("/login")
    public ResultOBJ login(@RequestBody UserBO userBO) {
        return ResultOBJ.success(userService.getUser(userBO));
    }

    @PostMapping
    public ResultOBJ addUser(@RequestBody UserBO userBO) {
        return ResultOBJ.success(userService.addUser(userBO));
    }

    @PutMapping("/{id}")
    public ResultOBJ updateUser(@PathVariable("id") Integer id, @RequestBody UserBO userBO) {
        userBO.setId(id);
        return ResultOBJ.success(userService.updateUser(userBO));
    }

    @PutMapping("/updatePwd/{id}")
    public ResultOBJ updatePwd(@PathVariable("id") Integer id, @RequestBody UpdatePwdDTO updatePwdDTO) {
        updatePwdDTO.setId(id);
        return ResultOBJ.success(userService.updatePwd(updatePwdDTO));
    }

    @DeleteMapping("{id}")
    public ResultOBJ deleteUser(@PathVariable Integer id) {
        return ResultOBJ.success(userService.deleteUser(id));
    }

    @PutMapping("/updateInfo/{id}")
    public ResultOBJ updateInfo(@PathVariable("id") Integer id, @RequestBody UpdateInfoDTO updateInfoDTO) {
        updateInfoDTO.setId(id);
        return ResultOBJ.success(userService.updateInfo(updateInfoDTO));
    }

    @PostMapping("/forgetPwd")
    public ResultOBJ forgetPwd(@RequestBody ForgetPwdDTO forgetPwdDTO) {
        return ResultOBJ.success(userService.forgetPwd(forgetPwdDTO));
    }

    @PostMapping("/forgetPwd/resetPwd")
    public ResultOBJ resetPwd(@RequestBody ResetPwdDTO resetPwdDTO) {
        return ResultOBJ.success(userService.resetPwd(resetPwdDTO));
    }
}
